package com.miguo.db;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteStatement;

import com.miguo.bean.AdvertBean;

import de.greenrobot.dao.AbstractDao;
import de.greenrobot.dao.Property;
import de.greenrobot.dao.internal.DaoConfig;

public class AdvertDao extends AbstractDao<AdvertBean, Void> {

    public static final String TABLENAME = "advert";

    /**
     * Properties of entity advert.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Id = new Property(0, Long.class, "id", false, "id");
        public final static Property Title = new Property(1, String.class, "title", false, "title");
        public final static Property Subject = new Property(2, String.class, "subject", false, "subject");
        public final static Property Item_pic_url = new Property(3, String.class, "item_pic_url", false, "item_pic_url");
        public final static Property Full_screen_pic_url = new Property(4, String.class, "full_screen_pic_url", false, "full_screen_pic_url");
        public final static Property Horizontal_pic_url = new Property(5, String.class, "horizontal_pic_url", false, "horizontal_pic_url");
        public final static Property Content = new Property(6, String.class, "content", false, "content");
        public final static Property Type = new Property(7, Integer.class, "type", false, "type");
        public final static Property Position = new Property(8, Integer.class, "position", false, "position");
        public final static Property Jump_type = new Property(9, Integer.class, "jump_type", false, "jump_type");
        public final static Property Start_time = new Property(10, Long.class, "start_time", false, "start_time");
        public final static Property End_time = new Property(11, Long.class, "end_time", false, "end_time");
        public final static Property Edit_time = new Property(12, Long.class, "edit_time", false, "edit_time");
        public final static Property Ordid = new Property(13, Integer.class, "ordid", false, "ordid");
        public final static Property Status = new Property(14, Integer.class, "status", false, "status");
    }

    ;


    public AdvertDao(DaoConfig config) {
        super(config);
    }

    public AdvertDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /**
     * Creates the underlying database table.
     */
    public static void createTable(SQLiteDatabase db, boolean ifNotExists) {
        String constraint = ifNotExists ? "IF NOT EXISTS " : "";
        db.execSQL("CREATE TABLE " + constraint + "'advert' (" + //
                "'id' INTEGER," + // 0: id
                "'title' TEXT," + // 1: title
                "'subject' TEXT," + // 2: subject
                "'item_pic_url' TEXT," + // 3: item_pic_url
                "'full_screen_pic_url' TEXT," + // 4: full_screen_pic_url
                "'horizontal_pic_url' TEXT," + // 5: horizontal_pic_url
                "'content' TEXT," + // 6: content
                "'type' INTEGER," + // 7: type
                "'position' INTEGER," + // 8: position
                "'jump_type' INTEGER," + // 9: jump_type
                "'start_time' INTEGER," + // 10: start_time
                "'end_time' INTEGER," + // 11: end_time
                "'edit_time' INTEGER," + // 12: edit_time
                "'ordid' INTEGER," + // 13: ordid
                "'status' INTEGER);"); // 14: status
    }

    /**
     * Drops the underlying database table.
     */
    public static void dropTable(SQLiteDatabase db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "'advert'";
        db.execSQL(sql);
    }

    /**
     * @inheritdoc
     */
    @Override
    protected void bindValues(SQLiteStatement stmt, AdvertBean entity) {
        stmt.clearBindings();

        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }

        String title = entity.getTitle();
        if (title != null) {
            stmt.bindString(2, title);
        }

        String subject = entity.getSubject();
        if (subject != null) {
            stmt.bindString(3, subject);
        }

        String item_pic_url = entity.getItem_pic_url();
        if (item_pic_url != null) {
            stmt.bindString(4, item_pic_url);
        }

        String full_screen_pic_url = entity.getFull_screen_pic_url();
        if (full_screen_pic_url != null) {
            stmt.bindString(5, full_screen_pic_url);
        }

        String horizontal_pic_url = entity.getHorizontal_pic_url();
        if (horizontal_pic_url != null) {
            stmt.bindString(6, horizontal_pic_url);
        }

        String content = entity.getContent();
        if (content != null) {
            stmt.bindString(7, content);
        }

        Integer type = entity.getType();
        if (type != null) {
            stmt.bindLong(8, type);
        }

        Integer position = entity.getPosition();
        if (position != null) {
            stmt.bindLong(9, position);
        }

        Integer jump_type = entity.getJump_type();
        if (jump_type != null) {
            stmt.bindLong(10, jump_type);
        }

        Long start_time = entity.getStart_time();
        if (start_time != null) {
            stmt.bindLong(11, start_time);
        }

        Long end_time = entity.getEnd_time();
        if (end_time != null) {
            stmt.bindLong(12, end_time);
        }

        Long edit_time = entity.getEdit_time();
        if (edit_time != null) {
            stmt.bindLong(13, edit_time);
        }

        Integer ordid = entity.getOrdid();
        if (ordid != null) {
            stmt.bindLong(14, ordid);
        }

        Integer status = entity.getStatus();
        if (status != null) {
            stmt.bindLong(15, status);
        }
    }

    /**
     * @inheritdoc
     */
    @Override
    public Void readKey(Cursor cursor, int offset) {
        return null;
    }

    /**
     * @inheritdoc
     */
    @Override
    public AdvertBean readEntity(Cursor cursor, int offset) {
        AdvertBean entity = new AdvertBean( //
                cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
                cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // title
                cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // subject
                cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // item_pic_url
                cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // full_screen_pic_url
                cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // horizontal_pic_url
                cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // content
                cursor.isNull(offset + 7) ? null : cursor.getInt(offset + 7), // type
                cursor.isNull(offset + 8) ? null : cursor.getInt(offset + 8), // position
                cursor.isNull(offset + 9) ? null : cursor.getInt(offset + 9), // jump_type
                cursor.isNull(offset + 10) ? null : cursor.getLong(offset + 10), // start_time
                cursor.isNull(offset + 11) ? null : cursor.getLong(offset + 11), // end_time
                cursor.isNull(offset + 12) ? null : cursor.getLong(offset + 12), // edit_time
                cursor.isNull(offset + 13) ? null : cursor.getInt(offset + 13), // ordid
                cursor.isNull(offset + 14) ? null : cursor.getInt(offset + 14) // status
        );
        return entity;
    }

    /**
     * @inheritdoc
     */
    @Override
    public void readEntity(Cursor cursor, AdvertBean entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setTitle(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setSubject(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setItem_pic_url(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setFull_screen_pic_url(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
        entity.setHorizontal_pic_url(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
        entity.setContent(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6));
        entity.setType(cursor.isNull(offset + 7) ? null : cursor.getInt(offset + 7));
        entity.setPosition(cursor.isNull(offset + 8) ? null : cursor.getInt(offset + 8));
        entity.setJump_type(cursor.isNull(offset + 9) ? null : cursor.getInt(offset + 9));
        entity.setStart_time(cursor.isNull(offset + 10) ? null : cursor.getLong(offset + 10));
        entity.setEnd_time(cursor.isNull(offset + 11) ? null : cursor.getLong(offset + 11));
        entity.setEdit_time(cursor.isNull(offset + 12) ? null : cursor.getLong(offset + 12));
        entity.setOrdid(cursor.isNull(offset + 13) ? null : cursor.getInt(offset + 13));
        entity.setStatus(cursor.isNull(offset + 14) ? null : cursor.getInt(offset + 14));
    }

    /**
     * @inheritdoc
     */
    @Override
    protected Void updateKeyAfterInsert(AdvertBean entity, long rowId) {
        // Unsupported or missing PK type
        return null;
    }

    /**
     * @inheritdoc
     */
    @Override
    public Void getKey(AdvertBean entity) {
        return null;
    }

    /**
     * @inheritdoc
     */
    @Override
    protected boolean isEntityUpdateable() {
        return true;
    }

}
